#!/bin/bash

echo "Building the project..."
npm run build

echo "Deploying the application..."
# 假设你的私钥文件路径为/home/yourusername/.ssh/id_rsa，如果在其他位置，请相应更改。

echo "Deploying folder .next..."
# 删除远程服务器上的旧文件
ssh  -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "rm -rf /data/h5/health/.next && mkdir /data/h5/health/.next"
# 传输新的应用文件到服务器
scp  -P 2002 -i ~/.ssh/id_rsa -r ./.next root@ssh.xunxinsoft.com:/data/h5/health/

echo "Deploying folder public..."
# 删除远程服务器上的旧文件
ssh  -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "rm -rf /data/h5/health/public && mkdir /data/h5/health/public"
# 传输新的应用文件到服务器
scp  -P 2002 -i ~/.ssh/id_rsa -r ./public root@ssh.xunxinsoft.com:/data/h5/health/

echo "Deploying package.json..."
# 删除远程服务器上的旧文件
ssh  -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "rm -rf /data/h5/health/package.json"
# 传输新的应用文件到服务器
scp  -P 2002 -i ~/.ssh/id_rsa -r ./package.json root@ssh.xunxinsoft.com:/data/h5/health/

ssh  -p 2002 -i ~/.ssh/id_rsa root@ssh.xunxinsoft.com "pm2 restart health"

echo "Deployment completed successfully."

# 等待用户按任意键后退出
read -p "Press any key to continue . . . " -n1 -s

echo # 产生一个新行
